// AutoSelSpring.cpp: implementation of the AutoSelSpring class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "AutoSelSpring.h"
#include "SpringSet.h"
#include "PersistentFacade.h"
#include "Part.h"
#include "SupportHanger.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

AutoSelSpring::AutoSelSpring()
{

}

AutoSelSpring::~AutoSelSpring()
{

}

Spring* AutoSelSpring::GetSpring()
{
	CString strSql;
	strSql.Format(_T("pgzmin <= %g and pgzmax >= %g"), this->WorkLoad(), this->WorkLoad());
	
	SpringSet* pSet = GetPersistentFacade().GetSpringSet();
	pSet->SetDataStandard(GetOwner()->GetStandard());
	pSet->GetSpringSet(strSql);

	Spring* pSpring = pSet->GetFirstSpring();
	while(pSpring != NULL)
	{
		if(!this->CanInSerial(pSpring))
		{
			delete pSpring;
			pSpring = NULL;
		}
		else
		{
			pSet->Close();
			return pSpring;
		}
		pSpring = pSet->GetNextSpring();
	}
	pSet->Close();

	return NULL;
}